<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="/luckydog/index">首页</a>
                        </li>
                        <li>
                            <a href="#">系统设置</a>
                        </li>
                        <li class="active"> 账号管理 </li>
                    </ul>
                </div>
                <!-- Page Body -->
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="widget">
                                <div class="widget-header ">
                                    <span class="widget-caption">列表</span>
                                </div>
                                <div class="widget-body">
                                 <div class="table-toolbar">
                                        <a id="editabledatatable_new" href="javascript:void(0);"  class="edit_account btn btn-default">
                                            添加账户
                                        </a>
                                    </div>
                                    <table class="table table-striped table-bordered table-hover" id="simpledatatable">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>邮箱账号</th>
                                                <th>角色</th>
                                                <th>姓名</th>
                                                <th>添加时间</th>
                                                <th>状态</th>
                                                <th>操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <tr>
                                            <?php if(!empty($account_list)):?>
                                                <?php foreach($account_list as $key=> $row):?>
                                                    <tr class="gradeX ">
                                                        <td class="center" style="text-align:center;width:40px;"><?php echo $key+1;?></td>
                                                        <td class="center"><?php echo $row['email']?></td>
                                                        <td class="center"><?php echo  $row['username']?></td>
                                                        <td class="center"><?php echo  $row['role_name']?></td>
                                                        <td class="center"><?php echo  date("Y-m-d h:i:s",$row['addtime'])?></td>
                                                        <td class="center"><?php if($row['status'] == 1){echo "启用";}else{echo "停用";}?></td>
                                                        <td class="center " data_id = "<?php echo $row['id'];?>">
                                                            <?php if($row['admin'] != 1):?>
                                                            <a href="javascript:;" class="edit_account">设置</a>&nbsp;|&nbsp;<a href="javascript:;" class="J_del">删除</a>
                                                            <br/><a href="javascript:;" class="J_Setstatus" status="<?php echo $row['status']?>"><?php if($row['status'] != 1){echo "启用";}else{echo "停用";}?></a>
                                                            <?php endif;?>
                                                        </td>
                                                    </tr>
                                                <?php endforeach;?>
                                            <?php endif;?>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
<script src="<?php echo STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script>
    $('.edit_account').on('click', function(){
        //iframe窗
        var id = $(this).parent().attr("data_id");
        var title = "修改账号";
        if(id == undefined){
            id = "";
            title = "添加账号";
        }
        console.log(id);
        layer.open({
            type: 2,
            title: title,
            shade: [0.5, '#000'],
            shadeClose: true,
            maxmin: true, //开启最大化最小化按钮
            area: ['550px', '350px'],
            content: '/luckydog/account/toSetAccount?id='+id
        });
    });


    $(document).ready(function() {
        $(".J_del").click(function() {
            var id = $(this).parent().attr("data_id");
            if (confirm("您确定要删除该账号吗？")) {
                $.post("/luckydog/account/delAccount", {"id":id}, function(res) {
                    if (res) {
                        window.location.reload();
                    }else{
                        alert("删除失败");
                    }
                });
            }
        });

        $(".J_Setstatus").click(function() {
            var id = $(this).parent().attr("data_id");
            var status = $(this).attr("status");
            if(status == 1){
                status = -1;
            }else{
                status = 1;
            }
            $.post("/luckydog/account/setStatus", {"id":id,"status":status}, function(res) {
                if (res) {
                    window.location.reload();
                }else{
                    alert("失败");
                }
            });
        });
    });

</script>


